<?php
class Club_model extends CI_Model {

   	function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
	
	function all(){
		$query =  $this->db->get('tb_club');
		return $query->result_array();
	}
	
	function insert_club($new){
		$this->db->insert('tb_club', $new);
	}
	
	function find($field, $value){
		$this->db->where($field, $value);
		$query =  $this->db->get('tb_club');
		return $query->result_array();
	}
	
	function get_periods(){
		$query =  $this->db->get('tb_periodo');
		return $query->result_array();
	}
	
	function insert_period($new){
		$this->db->insert('tb_periodo', $new);
	}
	
	function relate_period_to_club($new){
		$this->db->insert('tb_periodo_por_club', $new);
	}
	
	function find_period($field ,$value){
		$this->db->where($field, $value);
		$query =  $this->db->get('tb_periodo');
		return $query->result_array();
	}
	
	function update_period($id, $data){
		$this->db->where('id_periodo', $id);
		$this->db->update('tb_periodo', $data);
	}
	
	function get_linked_clubs_to_period($field, $value){
		$this->db->where($field, $value);
		$query =  $this->db->get('tb_periodo_por_club');
		return $query->result_array();
	}
	
	function link_period($id_period, $id_club){
		$data = array('ID_PERIODO' => $id_period, 'ID_CLUB' => $id_club);
		$this->db->insert('tb_periodo_por_club', $data);
	}
	
	function get_club_activites($id_club){
		$this->db->select( "a.*, i.* 
							FROM tb_actividad a, tb_integrante i
							WHERE i.ID_CLUB = ".$id_club."
							AND a.ID_INTEGRANTE = i.id_integrante");
		$query =  $this->db->get();
		return $query->result_array();
	}
}
?>










